# !/usr/bin/env python
# -*- coding: utf-8 -*-

# @File   : request.py
# @Time   : 2022/5/24 5:23 下午
# @Author : yujianhui
import json
import traceback
import requests
from frame.vo.reqvo import ReqVO


def get(req:ReqVO,token)->json:
    """
    get 请求
    :param url:
    :param headers:
    :return:
    """
    try:
        # verify=False， 不校验https的证书
        res=requests.get(req.url,req.headers,verify=False)
        return res.json()
    except Exception as e:
        traceback.print_exc()
        print('get请求失败，失败原因{}'.format(e))
        return None


def post(req:ReqVO,token)->json:
    """
    post 请求
    :param url:
    :param headers:
    :param body:
    :return:
    """
    url=req.url
    headers=req.headers
    body=req.body
    try:
        if 'application/json' in headers['Content-Type']:
            # verify=False， 不校验https的证书
            res=requests.post(url,headers,json=body,verify=False)
        else:
            res=requests.post(url,headers,data=body,verify=False)
        return res.json()
    except Exception as e:
        traceback.print_exc()
        print('get请求失败，失败原因{}'.format(e))
        return None